<template>
	<!-- 初鉴详情 -->
	<view>
		<view class="page">
			<view class="topShell">
				<image class="titleImg" mode="aspectFill" :src="classifyImg"></image>
				<view class="contentShell">
					<image class="logo" mode="widthFix" src="/static/image/wineIcon.png"></image>
					<view class="classifyName">{{info.goodsName}}</view>
				</view>
			</view>
			<view class="bottomShell">
				<view class="bottomTitle">鉴别图片</view>
				<view class="imgListShell">
					<image mode="aspectFill" @click="preHandle(item)" class="img" v-for="(item,index) in info.pictures"
						:key="index" :src="item.picture"></image>
				</view>
			</view>
			<!-- 	<view class="bottomShell">
				<view class="bottomTitle">商品参数</view>
				<view class="textShell">
					<view class="textText">{{(info.content =='' || !info.content) ? '无参数' :item.content}}</view>
				</view>
			</view> -->
			<view class="bottomShell">
				<view class="bottomTitle">备注</view>
				<view class="remarkShell">
					<view class="remarkText">{{info.remarks}}</view>
				</view>
			</view>
			<view class="bottomShell">
				<view class="bottomTitle">预估价格</view>
				<view class="priceShell">
					<input class="input" @input="checkNum($event)" v-model="subPrice" />
					<view class="inputText">元</view>
				</view>
			</view>
				<view class="bottomShell">
				<view class="bottomTitle">鉴定理由</view>
				<view class="textShell">
					<textarea auto-height class="Reason" placeholder="请输入鉴定理由" v-model="reason" />
				</view>
			</view>
		</view>
		<view class="buttonShell">
			<view class="button" @click="appraisalHandle(2)">无法鉴定</view>
			<view class="button" @click="appraisalHandle(1)">鉴定为真品</view>
		</view>
	</view>
</template>

<script>
	const app = getApp()
	export default {
		data() {
			return {
				info: {},
				subPrice: '', //预估价格
				classifyImg: "", //分类图片
				goodsImg: '',
				userData:{},
				reason:'' //鉴定理由
			}
		},
		onLoad(options) {
			this.id = options.id
			this.getDetail(options.id)
			this.classifyImg = app.globalData.picture
			this.userData = uni.getStorageSync('userData').user
		    // console.log(this.userData)
		},
		methods: {
			checkNum(e) {
				let isPrice = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/
				let val = e.target.value
				// console.log(val)
				if (isPrice.test(val)) {
					this.$nextTick(() => {
						this.subPrice = val;
					})
				} else {
					this.$nextTick(() => {
						this.subPrice = '';
					})
				}


			},
			// 提交初鉴
			appraisalHandle(type) {
				if (type == 1 && (this.subPrice == '' || !this.subPrice)) {
					uni.showToast({
						title: "请填写预估价格",
						icon: "none",
						mask: true,
						duration: 1200
					})
				} else {
					this.http({
						url: "/appraisal/appraisal",
						data: {
							id: this.id, //订单id
							userId: this.userData.customerId, //操作人id
							IdentificationResults: type, //1真  2无法鉴定
							evaluation: this.subPrice, //鉴定估价
							reason: this.reason, //鉴定理由
						},
						method: "POST",
						success: res => {
							if (res.code == 200) {
								uni.showToast({
									title: "操作成功",
									mask: true,
									icon: "success",
									duration: 1500
								})
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									})
								}, 1500)
							}
						}
					})
				}
			},
			// 预览图片
			preHandle(item) {
				const arr = []
				this.info.pictures.forEach(item => {
					arr.push(item.picture)
				})
				// console.log()
				uni.previewImage({
					current: item.picture,
					urls: arr,
					success: (res) => {
						return true
					},
					fail: (err) => {
						console.log(err)
						uni.showToast({
							title: "图片好像出了问题",
							icon: "none",
							mask: true,
							duration: 1200
						})
					}
				})
			},
			// 获取鉴定详情
			getDetail(id) {
				this.http({
					url: "/appraisal/info",
					data: {
						id
					},
					method: "POST",
					success: res => {
						if (res.code == 200) {
							this.info = res.data
							this.goodsImg = res.data.pictures[0].picture
						}
					}
				})
			}
		}
	}
</script>

<style scoped>
	.page {
		width: 100%;
		box-sizing: border-box;
		padding: 0 40rpx;
		margin-bottom: 40rpx;
	}

	.topShell {
		width: 100%;
		display: flex;
		align-items: center;
		padding-bottom: 60rpx;
	}

	.titleImg {
		width: 160rpx;
		height: 160rpx;
		display: block;
	}

	.contentShell {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-left: 24rpx;
	}

	.logo {
		width: 85rpx;
		height: 85rpx;
		border-radius: 50%;
	}

	.classifyName {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: #000000;
	}

	.bottomShell {
		width: 100%;
		margin-top: 40rpx;
	}

	.bottomTitle {
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #000000;
		padding-bottom: 30rpx;
	}

	.imgListShell {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.img {
		width: 150rpx;
		height: 150rpx;
		display: block;
		border-radius: 8rpx;
	}

	.textShell {
		width: 100%;
		/* min-height: ; */
		box-sizing: border-box;
		padding: 20rpx 10rpx;
		background-color: #F3F3F3;
		border-radius: 9rpx;
	}
    .Reason{
		min-height: 240rpx;
	}
	.textText {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: rgba(30, 37, 43, 0.65);
	}

	.remarkShell {
		width: 100%;
		height: 140rpx;
	}

	.remarkText {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: rgba(30, 37, 43, 0.65);
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 4;
		/*想省略几行就写几*/
		-webkit-box-orient: vertical;
	}

	.priceShell {
		display: flex;
		align-items: center;
		border-bottom: 0.5px solid #d9d9d9;
	}

	.input {
		width: 90%;
		border: none;
	}

	.inputText {
		font-size: 28rpx;
		font-family: Source Han Sans CN;
		font-weight: 400;
		color: rgba(30, 37, 43, 0.65);
	}

	.buttonShell {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 40rpx;
		margin-bottom: 30rpx;
	}

	.button {
		width: 90%;
		margin: 0 auto;
		margin-top: 30rpx;
		padding: 20rpx 0;
		text-align: center;
		border-radius: 4rpx;
		background-color: #E32929;
		font-size: 32rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>
